package com.joinval.config;

import com.joinval.common.utils.SpringContextUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

/**
 * @Author zhizuntop
 * @create 2023/12/11 15:19
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "spring.mail")
public class MailConfiguration {

//    MailProp mailProp = SpringContextUtils.getBean(MailProp.class);

    private String host;
    private int port;
    private String username;
    private String password;
    private String protocol;

    @Bean("javaMailSender")
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost(host);
        mailSender.setPort(port);

        mailSender.setUsername(username);
        mailSender.setPassword(password);

        mailSender.setDefaultEncoding("UTF-8");
        mailSender.setProtocol(protocol);


//        Properties props = mailSender.getJavaMailProperties();
//        props.put("mail.transport.protocol", "smtp");
//        props.put("mail.smtp.auth", "true");
//        props.put("mail.smtp.starttls.enable", "true");
        return mailSender;
    }
}
